<?php
class Product_model extends MY_Model {
    protected $table = 'tbl_product';
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    public function get_info($col, $col_val , $get_col)
            
    {
        $cate = $this->get_one($this->table,$col,$col_val);
       
        if($cate)
        {
            foreach ($cate as $val)
            {
                    return $val[$get_col];
                
            }
        }
    }
    public function get_info_img($col, $col_val , $get_col)
            
    {
        $cate = $this->get_one('tbl_pro_img', $col, $col_val);
       
        if($cate)
        {
            foreach ($cate as $val)
            {
                    return $val[$get_col];
                
            }
        }
    }
    public function get_id_max()
    {
        $array_pro = $this->list_tab($this->table); 
        $ids = array();
        foreach ($array_pro as $pro)
        {
            $ids[] = $pro['pro_id'];
        }
        
            return max($ids);
       
    }
    public function list_img($pro_id = '', $img_main = 0)
    {
        if($pro_id != '')
        {
            $this->db->select();
            $this->db->from('tbl_pro_img');
            $this->db->where('pro_id', $pro_id);
            $this->db->where('pro_img_main', $img_main);
            if($img_main == 1)
            {
                $this->db->where('pro_img_main', $img_main);
            }
            $query = $this->db->get();
            $data = array();
            if($query->num_rows() > 0)
            {
                $data =  $query->result_array();
            }
            return $data;
        }
    }
    public function check_img($pro_id = '')
    {
        if($pro_id != '')
        {
            $this->db->select();
            $this->db->from('tbl_pro_img');
            $this->db->where('pro_id', $pro_id);
            $this->db->where('pro_img_main', 1);
            $query = $this->db->get();
            if($query->num_rows() > 0)
            {
                return TRUE;
            }
            else
            {
                return FALSE;
            }
        }
    }
    public function detele_img($pro_id)
    {
        $this->db->where('pro_id', $pro_id);
        $this->db->where('pro_img_main', 1);
        $this->db->delete('tbl_pro_img');
    }
    public function del_all()
    {
        $sql = "DELETE FROM tbl_slider";
        $this->db->query($sql);
        //mysql_query($sql);
    }
   
     
}